#include <stdio.h>
#include "communication.h"
#include "drv_usart1.h"
#include "drv_can.h"
#include "XgUpperMonitor.h"
#include "Ymodem.h"
#include "systemdata.h"
#include "CanCharger.h"
#include "Iot_control.h"
#include "monitor_platform_iot.h"
#include "MtModebus.h"
#include "ModBus.h"
#include "ZhiXiangModBus.h"

void external_communicator_process(void){
	SysRunData_t *runinfo = getSysRunData();
	UsartRxInfo_t *rx_info2 = get_uart2_info();
	UsartRxInfo_t *rx_info4 = get_uart4_info();
	CanTransData_t *can_rx_info = getCanRecvInfo();
	if(rx_info4->recv_ok_flag == 1){
		runinfo->comLinkState.Bits.rs485_link = 1;
	}
	
	if(runinfo->sysSwState.bits.SW_OTA == 0){//升级开关没打开
		if(rx_info4->recv_ok_flag == 1){//
			modbus_data(rx_info4->recv_buf,rx_info4->recv_len,4);
			mt_charger_data(rx_info4->recv_buf,rx_info4->recv_len,4);
			sket_recv_data(rx_info4->recv_buf,rx_info4->recv_len,4);
			zhiXiangModbus_data(rx_info4->recv_buf,rx_info4->recv_len,4);
			rx_info4->recv_len = 0;
			rx_info4->recv_ok_flag = 0;
		}
	}else{
		ymodem_update_process();
	}
	if(rx_info2->recv_ok_flag == 1){//
		modbus_data(rx_info2->recv_buf,rx_info2->recv_len,2);
		mt_charger_data(rx_info2->recv_buf,rx_info2->recv_len,2);
		sket_recv_data(rx_info2->recv_buf,rx_info2->recv_len,2);
		rx_info2->recv_len = 0;
		rx_info2->recv_ok_flag = 0;
	}
}
